<?php

namespace Maestros\Controller;

use Maestros\Controller\GenericController;

class CuposSeccionController extends GenericController {

    public function __construct() {
        
    }

//Incompleto
    public function get($id) {
        /*
         * Datos del sexo COMPLETO (con el usuario) //por ahora :)
         * FALTAN LAS DEMAS FORANEAS
         * Ej: http://localhost/UptaebBackend/public/maestros/sexo/1
         * Rsp: {"success":true,"data":[{"id":1,"login":"07443224","password":"123","estado":1,"_grupo":{"id":1,"nombre":"Estudiante","detalle":"Estudiantes activos"}}],"total":1}
         */
        $id = $this->params()->fromRoute('id');
        $output = $this->getCuposSeccionService()->getRegistro($id);
        return $this->convertirArrayAJson($output);
    }

    /**
     * Return list of resources
     * @return mixed
     */
    public function getList($id = 1, $param1 = 1, $param2 = 1, $param3 = 1) {
        $id = $this->params()->fromRoute('id');
        $param1 = $this->params()->fromRoute('param1');
        switch ($id) {
            case (0):
                /*
                 * Datos de la  sexo sin los objetos foraneos
                 * Ej: http://localhost/UptaebBackend/public/maestros/sexo/0/1
                 * Rsp: {"success":true,"data":[{"id":"1","_estado":"1","descripcion":"NO INDICA"}],"total":1,"mensaje":null}
                 */
                $id = $this->params()->fromRoute('param1');
                $output = $this->getCuposSeccionService()->getRegistro($id);
                break;
            default:
                return $param1;
        }
        return $this->convertirArrayAJson($output);
    }

    public function update($data) {
        $id = $this->params()->fromRoute('id');
        $idIngresoMalla = $this->params()->fromRoute('param1');
        $idLapso = $this->params()->fromRoute('param2');
        $idCondicionMatricular = $this->params()->fromRoute('param3');
        $idTrayectoSemestre = $this->params()->fromRoute('param4');
        $idTurno = $this->params()->fromRoute('param5');
        $idSeccion = $this->params()->fromRoute('param6');
        $idControlInscripcion = $this->params()->fromRoute('param7');
        // Guardar el registro
        $datosAcademicos = new DatosAcademicos;
        $datosAcademicos->setId(0);
        $datosAcademicos->setIngresoMalla($idIngresoMalla);
        $datosAcademicos->setLapso($idLapso);
        $datosAcademicos->setCondicionMatricular($idCondicionMatricular);
        $datosAcademicos->setTrayectoSemestre($idTrayectoSemestre);
        $datosAcademicos->setTurno($idTurno);
        $datosAcademicos->setSeccion($idSeccion);
        $datosAcademicos->setControlInscripcion($idControlInscripcion);
        $data = $datosAcademicos->objectToArrayBD();
        $result = $this->getDatosAcademicosService()->createRegistro($data);
        $response = $this->getResponseWithHeader();
        $response->setContent($result);
        return $response;
    }

}
